<template>
  <div class="box-list-container">
    <div class="box-query-form">
      <el-form :model="queryParam" label-width="auto" label-position="right" :gutter="24">
        <el-row>
          <el-col :xl="6" :lg="6" :md="12" :sm="24">
            <el-form-item label="游戏:">
              <el-select v-model="queryParam.gid" clearable placeholder="请选择">
                <el-option v-for="item in gameList" :key="item.id" :label="item.gameName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xl="6" :lg="6" :md="12" :sm="24">
            <el-form-item label="兑换码:">
              <el-input v-model="queryParam.code" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :xl="6" :lg="6" :md="12" :sm="24">
            <el-form-item label="充值账号:">
              <el-input v-model="queryParam.topupAccount" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :xl="6" :lg="6" :md="12" :sm="24" class="table-search-btn">
            <el-button icon="el-icon-refresh" @click="searchReset">重置</el-button>
            <el-button type="primary" icon="el-icon-search" @click="searchQuery">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="box-table">
      <div class="table-title">
        <div class="table-title-left">
          充值记录
        </div>
        <div>
          <!-- <el-button plain class="btnAdd" icon="el-icon-plus" @click="handleAdd('新增')">新增</el-button> -->
        </div>
      </div>
      <el-table ref="table" :data="dataSource">
        <el-table-column fixed="left" prop="id" label="ID" width="60" />
        <el-table-column fixed="left" prop="gameName" label="游戏" min-width="150">
          <template slot-scope="scope">
            <div class="imgAndText">
              <img v-if="getGameInfo(scope.row.gid).imgUrl && getGameInfo(scope.row.gid).imgUrl.length" class="img" :src="getGameInfo(scope.row.gid).imgUrl">
              <img v-else src="@/assets/game.png" class="img">
              <div class="info">
                <div class="top">{{ getGameInfo(scope.row.gid).gameName }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="code" label="兑换码" min-width="320">
          <template slot-scope="scope">
            <el-tag type="info" @click="codeClick(scope.row.code)">{{ scope.row.code }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="topupAccount" label="充值账号" width="150" />
        <el-table-column prop="accountType" label="账号类型" width="120" />
        <el-table-column prop="gameArea" label="游戏区服" width="120" />
        <el-table-column prop="deviceType" label="设备类型" width="150" />
        <el-table-column prop="createTime" label="更新时间" width="170" />
      </el-table>
      <div class="box-paging">
        <Pagination
          v-show="ipagination.total > 0"
          layout="total, sizes, prev, pager, next"
          :total="ipagination.total"
          :page.sync="ipagination.pageNum"
          :limit.sync="ipagination.pageSize"
          @pagination="loadData"
        />
      </div>
    </div>
    <handleDialog ref="modalForm" @ok="modalFormOk" />
  </div>
</template>

<script>
import { listMixin } from '@/mixins/listMixin'
import Pagination from '@/components/Pagination'
import handleDialog from './components/handleDialog'

export default {
  components: {
    Pagination,
    handleDialog
  },
  mixins: [listMixin],
  data() {
    return {
      guidFieldName: 'id',
      ipagination: {
        pageNum: 1,
        pageSize: 100,
        total: 0
      },
      queryParam: {},
      gameList: this.$ls.get('GAME_LIST') || [],
      userInfo: this.$ls.get('USER_INFO') || {},
      url: {
        list: 'rechargeRecord.aspx?action=GetList',
        delete: 'rechargeRecord.aspx?action=Delete',
        deleteBatch: 'rechargeRecord.aspx?action=DeleteBatch'
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    async codeClick(c) {
      try {
        await navigator.clipboard.writeText(c)
        this.$message.success('复制成功：' + c)
      } catch (err) {
        this.$message.warning('无法复制文本: ' + err)
      }
    },
    getGameInfo(gid) {
      if (!gid) {
        return {}
      }
      const obj = this.gameList.find(v => String(v.id) === String(gid))
      if (obj) {
        return obj
      }
    },
    // 重置
    searchReset() {
      this.queryParam = {}
      this.loadData(1)
    }
  }
}
</script>

<style lang="scss" scoped>
.imgAndText{
  display: flex;
  align-items: center;
  .img {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    margin-right: 16px;
  }
  .info {
    display:flex;
    flex-direction:column;
    justify-content:space-between;
    color: #333;
    .top{
      font-weight: bold;
      margin: 2px 0;
    }
  }
}
.resTag{
  display: inline-block;
  line-height: 24px;
  padding: 4px 10px;
  border-radius: 2px;
}
.resTag1{
  color: #999;
  background-color: #e7fae7;
}
.resTag2{
  color: #006400;
  background-color: #ffe6e7;
}
.code{
  padding: 10px 0;
}
</style>

